package cn.itcast.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class EnCodingFilter implements Filter {
    private String enCoding;
    @Override
    public void init(FilterConfig config) throws ServletException {
         enCoding = config.getInitParameter("encoding");
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
          req.setCharacterEncoding(enCoding);
          resp.setContentType("text/html;charset="+enCoding);
          chain.doFilter(req,resp);
    }

    @Override
    public void destroy() {

    }
}
